/**
 * Created by asus on 2018/9/24.
 */
define(['jquery', 'cookie'], function ($) {
  var password = $(".password input")
  var newPassword = $(".newPassword input")
  var rePassword = $(".rePassword input")
  var toast = $('.toast')
  // 密码正则
  var regPswd = /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,20}$/
  $("#save-btn").click(function () {
    if (!validateFrom()) {
      return
    }
    var id = JSON.parse($.cookie("userToken")).id
    //$.ajax({
    //  url: '/',
    //  type:'POST',
    //  data: {
    //    id: id,
    //    oldPassward: password.val(),
    //    newPassword: newPassword.val()
    //  },
    //  success: function (res) {
    //
    //  }
    //})
    window.location.href = "complete-personal-data.html"
  })
  function validateFrom() {
    var passwordVal = password.val()
    var newPasswordVal = newPassword.val()
    var rePasswordVal = rePassword.val()

    if (!passwordVal) {
      toast.css('display', 'block').html('请输入旧密码').fadeIn().fadeOut(2000);
      return
    } else if (!regPswd.test(passwordVal)) {
      toast.css('display', 'block').html('密码格式不正确').fadeIn().fadeOut(2000);
      return
    }
    if (!newPasswordVal) {
      toast.css('display', 'block').html('请输入新密码').fadeIn().fadeOut(2000);
      return
    } else if (!regPswd.test(newPasswordVal)) {
      toast.css('display', 'block').html('密码格式不正确').fadeIn().fadeOut(2000);
      return
    }
    if (!rePasswordVal) {
      toast.css('display', 'block').html('请再次输入密码').fadeIn().fadeOut(2000);
      return
    }
    if (newPasswordVal !== rePasswordVal) {
      toast.css('display', 'block').html('两次密码不一致').fadeIn().fadeOut(2000);
      return
    }
    return true
  }
})